//
//  NewsListViewCell.swift
//  MyNews
//
//  Created by DF-Mac on 16/12/13.
//  Copyright © 2016年 DF-Mac. All rights reserved.
//

import UIKit


class NewsListViewCell: UITableViewCell {
    
    var newsDataModel : NewsDataModel?{
        didSet{
            newsTitleLabel?.text=newsDataModel?.title
            newsSubTitleLabel?.text=newsDataModel?._description
            newsDateLabel?.text=newsDataModel?.ctime
            //        newsImageView?.image=UIImage.init(named: "placeholderCollect")
            let newsImageUrl = URL(string: (newsDataModel?.picUrl)!)
            //print(newsImageUrl);
            newsImageView?.kf.setImage(with: newsImageUrl, placeholder: UIImage.init(named: "placeholderCollect"), options: nil, progressBlock: nil, completionHandler: nil)
        }
    }
    
    
    var newsImageView : UIImageView?
    var newsTitleLabel : UILabel?
    var newsSubTitleLabel : UILabel?
    var newsDateLabel : UILabel?
    

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.initialUI()
        
    }
    func initialUI() -> () {
        newsImageView=UIImageView(frame: CGRect(x: UIScreen.main.bounds.size.width-100, y: 10, width: 80, height: 80))
        newsImageView?.layer.masksToBounds=true
        contentView.addSubview(newsImageView!)
        
        newsTitleLabel=UILabel.init(frame: CGRect(x: 10, y: 10, width: UIScreen.main.bounds.size.width-120, height: 30))
        newsTitleLabel?.font=UIFont.systemFont(ofSize: 18)
        newsTitleLabel?.textAlignment=NSTextAlignment.center
        newsTitleLabel?.textColor=UIColor.blue
        contentView.addSubview(newsTitleLabel!)
        
        
        newsDateLabel=UILabel.init(frame: CGRect(x: 10, y: 45, width: UIScreen.main.bounds.size.width-120, height: 20))
        newsDateLabel?.font=UIFont.systemFont(ofSize: 12)
        newsDateLabel?.textAlignment=NSTextAlignment.center
        newsDateLabel?.textColor=UIColor.gray
        contentView.addSubview(newsDateLabel!)
        
        newsSubTitleLabel=UILabel.init(frame: CGRect(x: 10, y: 70, width: UIScreen.main.bounds.size.width-120, height: 30))
        newsSubTitleLabel?.font=UIFont.systemFont(ofSize: 14)
        newsSubTitleLabel?.textAlignment=NSTextAlignment.center
        newsSubTitleLabel?.textColor=UIColor.lightGray
        contentView.addSubview(newsSubTitleLabel!)

    }
    ///self.ctime=ctime ?? ""
//    self.picUrl=picUrl ?? ""
//    self.url=url ?? ""
//    self.title=title ?? ""
    
    func setValueForCell(dic:NSDictionary) -> () {
        newsTitleLabel?.text=dic.object(forKey: "title") as! String?
        newsSubTitleLabel?.text=dic.object(forKey: "") as! String?
        newsDateLabel?.text=dic.object(forKey: "ctime") as! String?
//        newsImageView?.image=UIImage.init(named: "placeholderCollect")
        let newsImageUrl = URL(string: dic.object(forKey: "picUrl") as! String)
        newsImageView?.kf.setImage(with: newsImageUrl, placeholder: UIImage.init(named: "placeholderCollect"), options: nil, progressBlock: nil, completionHandler: nil)
        
        
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
